/*
 *	This file is part of Lounge-Cast.
 *
 *  Author:  	Markus Moormann
 *	E-mail:  	mmoorman@uni-osnabrueck.de
 *	Copyright:	University of Osnabrueck (Zentrum Virtuos)
 * 	Website:	www.uni-osnabrueck.de
 *	Date:		16.02.2011
 *
 *	Lounge-Cast is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *	Lounge-Cast is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Lounge-Cast.  If not, see <http://www.gnu.org/licenses/>.
 */
package webservice.functions;

import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.ProduceMime;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;

import webservice.helper.HelperClass;
import webservice.vo.Preferences;

/**
 * REST-Service class for getting settings-xml for client
 *
 * @author Markus Moormann
 */
@Path("/preferences")
public class GetPreferencesXMLResource {
	
	/**
	 * generates XML file for client-settings
	 * called as http://example.org/webservice/preferences?playerId=&apiKey=
	 * 
	 * @param playerId the id of the player
	 * @param apiKey the api key to authenticate
	 * @return an XML document containing the nescassaray information
	 */
	@GET
	@ProduceMime("text/xml")
	public Preferences getPreferencesXML(@QueryParam("playerId") @DefaultValue("") String playerId,
										 @QueryParam("apiKey") @DefaultValue("") String apiKey) {
		if(!apiKey.equals(HelperClass.getProperty("apiKey"))) {
			throw new WebApplicationException(Response.Status.FORBIDDEN);
		}
		return new Preferences(HelperClass.getProperty("webserviceURL"), 
							   HelperClass.getProperty("apiKey"), 
							   playerId);
	}

}
